package com.lovo.pz.role;

import com.lovo.pz.util.GameMusic;
import com.lovo.pz.util.GameUtil;
import com.lovo.pz.window.GamePanel;

import java.awt.*;

/**
 * 豌豆射手角色
 * @author 白德柯
 *
 */
public class PeaShooterRole extends PlantRole{
    public PeaShooterRole(Component component){
        super(component);
    }
    @Override
    public void initRole() {
        setHp(20);
        setCost(100);
        setPlantType(PlantCardRole.PEA_SHOOTER);
        setRoleWidth(GameUtil.peaShooterImage.getWidth(getComponent()));
        setRoleHeight(GameUtil.peaShooterImage.getHeight(getComponent()));
    }

    @Override
    public void paintRole(Graphics g) {
        // 开启半透明
        if(getRunStatus() == PLANT_TEMP){
            GameUtil.setAlpha(g,0.5f);
        }
        g.drawImage(GameUtil.peaShooterImage,getRoleX(),getRoleY(),getComponent());
        // 关闭半透明
        GameUtil.setAlpha(g,1);
    }

    @Override
    public void action() {
        if(getHp() < 0){
            setRunStatus(ROLE_END);
        }
        if(getRunStatus() == SEND_BULLET){
            // 每隔多少时间发射一个子弹
            if(GameUtil.delay(1000,this,"sendPeaShooterBullet")){
                GameMusic.playSingleMusic(GameUtil.peaShooterBulletMusic);
                PeaShooterBulletRole peaShooterBulletRole = new PeaShooterBulletRole(getComponent());
                peaShooterBulletRole.setRoleX(getRoleX() + 30);
                peaShooterBulletRole.setRoleY(getRoleY() + 10);
                GamePanel gamePanel = (GamePanel) getComponent();
                gamePanel.getPeaShooterBulletRoleList().add(peaShooterBulletRole);
            }
        }
    }
}
